//
//  HCStarDidViewController.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/20.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCStarDidViewController.h"

#import "HCStarDidView.h"

#import "HCStarDidModel.h"

@interface HCStarDidViewController () <HCStarDidViewClicked> {
    HCStarDidData *data;
    MBProgressHUD *starHud;
}

@end

@implementation HCStarDidViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.textTitle = @"星级评价";
    
    data = (HCStarDidData *)self.parameterObject;
    self.dataRequest.delegate = self;
    
    HCStarDidView *didView = [[HCStarDidView alloc] initWithFrame:CGRectMake(0, 0, self.centerView.frame.size.width, self.centerView.frame.size.height)];
    didView.delegate = self;
    didView.model = data;
    [self.centerView addSubview:didView];
    
    // Do any additional setup after loading the view.
}

-(void)sureClicked:(NSString *)type andStar:(NSString *)star {
    starHud = [MBProgressHUD showHUDAddedTo:self.centerView animated:YES];
    [self.dataRequest postHC_HomeStar:data.aid star:star type:type];
}

-(void)dataRequesterFinish:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveDictionary:(NSDictionary *)dictionary {
    NSLog(@"评价提交成功:%@",dictionary);
    [starHud hide:YES];
    if ([dictionary[@"stat"] integerValue] == 200) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"评价成功" message:nil preferredStyle:UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self.navigationController popViewControllerAnimated:YES];
        }]];
//        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//        }]];
        [self presentViewController:alert animated:YES completion:NULL];
    }else{
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"评价失败" message:nil preferredStyle:UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self.navigationController popViewControllerAnimated:YES];
        }]];
//        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//        }]];
        [self presentViewController:alert animated:YES completion:NULL];
    }
    
}

-(void)dataRequesterFail:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveErrorDictionary:(NSDictionary *)dictionary {
    NSLog(@"评价提交失败");
    [starHud hide:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
